package com.wjy.simple.fragment;

import android.media.Image;
import android.os.Bundle;
import android.support.v4.content.Loader;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wjy.sfhcore.engine.BaseAsyncTaskLoader;
import com.wjy.sfhcore.ui.fragment.list.BaseListAdapter;
import com.wjy.sfhcore.ui.fragment.list.BaseStickyListFragment;
import com.wjy.simple.R;
import com.wjy.simple.adapter.StickyListAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjingyuan on 15/8/1.
 */
public class StickListDemoFragment extends BaseStickyListFragment<String, List<String>> {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_sticky_list_demo, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        loadData();
    }


    @Override
    protected BaseListAdapter<String> getAdapter() {
        return new StickyListAdapter(baseActivity);
    }

    @Override
    protected void getDatas() {
        getLoaderManager().restartLoader(0, null, this);
    }

    @Override
    protected void loadFinished(int action, List<String> result) {
        changeViewState(LoadResult.LOAD_SUCCESS);
        setTotalPages(10);
        setDatas(result);
    }


    @Override
    protected View initHeaderChildView() {
        ImageView iv = new ImageView(baseActivity);
        iv.setImageResource(R.mipmap.ic_launcher);
        return iv;

    }

    @Override
    public Loader<List<String>> onCreateLoader(int action, Bundle bundle) {
        return new BaseAsyncTaskLoader<List<String>>(baseActivity) {
            @Override
            public List<String> loadInBackground() {
                List<String> data = new ArrayList<>();
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                data.add("服务紧固件危机感");
                return data;
            }
        };
    }
}
